package com.zp.base.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.zp.base.entity.bo.OperationDictIcd10Bo;
import com.zp.base.entity.vo.OperationDictIcd10Vo;
import com.zp.base.service.IOperationDictIcd10Service;
import com.zp.common.core.controller.BaseController;
import com.zp.common.core.entity.R;
import com.zp.common.core.validate.AddGroup;
import com.zp.common.core.validate.EditGroup;
import com.zp.common.excel.utils.ExcelUtil;
import com.zp.common.log.annotation.Log;
import com.zp.common.log.enums.BusinessType;
import com.zp.common.myBatis.core.page.PageQuery;
import com.zp.common.myBatis.core.page.TableDataInfo;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;

/**
 * 手术基础字典多个类型控制器
 * 前端访问路由地址为:/admin/operationDictIcd10
 *
 * @author zhang peng
 * @date 2023-01-11
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/operationDictIcd10")
public class OperationDictIcd10Controller extends BaseController {

    private final IOperationDictIcd10Service iOperationDictIcd10Service;

    /**
     * 查询手术基础字典多个类型列表 (分页)
     */
    @SaCheckPermission("base:operationDictIcd10:list")
    @GetMapping("/selectPage")
    public TableDataInfo<OperationDictIcd10Vo> selectPage (OperationDictIcd10Bo bo, PageQuery pageQuery) {
        return iOperationDictIcd10Service.queryPageList(bo, pageQuery);
    }

    /**
     * 查询手术基础字典多个类型列表 (不分页)
     */
    @SaCheckPermission("base:operationDictIcd10:list")
    @GetMapping("/list")
    public R<List<OperationDictIcd10Vo>> list (OperationDictIcd10Bo bo) {
        List<OperationDictIcd10Vo> list = iOperationDictIcd10Service.queryList(bo);
        return R.ok(list);
    }

    /**
     * 导出手术基础字典多个类型列表
     */
    @SaCheckPermission("base:operationDictIcd10:export")
    @Log(title = "手术基础字典多个类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export (OperationDictIcd10Bo bo, HttpServletResponse response) {
        List<OperationDictIcd10Vo> list = iOperationDictIcd10Service.queryList(bo);
        ExcelUtil.exportExcel(list, "手术基础字典多个类型", OperationDictIcd10Vo.class, response);
    }

    /**
     * 获取手术基础字典多个类型详细信息
     *
     * @param operationDictId 主键
     */
    @SaCheckPermission("base:operationDictIcd10:query")
    @GetMapping("/{operationDictId}")
    public R<OperationDictIcd10Vo> getInfo (@NotNull(message = "主键不能为空") @PathVariable String operationDictId) {
        return R.ok(iOperationDictIcd10Service.queryById(operationDictId));
    }

    /**
     * 新增手术基础字典多个类型
     */
    @SaCheckPermission("base:operationDictIcd10:add")
    @Log(title = "手术基础字典多个类型", businessType = BusinessType.INSERT)
    @PostMapping()
    public R<Void> add (@Validated(AddGroup.class) @RequestBody OperationDictIcd10Bo bo) {
        return toAjax(iOperationDictIcd10Service.insertByBo(bo) ? 1 : 0);
    }

    /**
     * 修改手术基础字典多个类型
     */
    @SaCheckPermission("base:operationDictIcd10:edit")
    @Log(title = "手术基础字典多个类型", businessType = BusinessType.UPDATE)
    @PutMapping()
    public R<Void> edit (@Validated(EditGroup.class) @RequestBody OperationDictIcd10Bo bo) {
        return toAjax(iOperationDictIcd10Service.updateByBo(bo) ? 1 : 0);
    }

    /**
     * 删除手术基础字典多个类型
     *
     * @param operationDictIds 主键串
     */
    @SaCheckPermission("base:operationDictIcd10:remove")
    @Log(title = "手术基础字典多个类型", businessType = BusinessType.DELETE)
    @DeleteMapping("/{operationDictIds}")
    public R<Void> remove (@NotEmpty(message = "主键不能为空") @PathVariable String[] operationDictIds) {
        return toAjax(iOperationDictIcd10Service.deleteWithValidByIds(Arrays.asList(operationDictIds), true) ? 1 : 0);
    }
}
